<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	$("#addrepositoryTitles").click(function(){
		var addid=document.getElementById('editrepository');
		document.getElementById('repositoryfrom').reset();
		 dialog = art.dialog({
		        title: "新增清单标题",
		        lock:true,
		        content: addid
		    });
	});
})
function del(id){
	 if(confirm("是否确认删除？")){
		 $.ajax({
			   type: "post",
			   dataType:"json",
			   url: "delrepositorytitle.do",
			   data:{id:id},
			   success: function(data){//成功的时候调用
				   if(data==1){
					   art.dialog.alert("删除成功",function(){
					   		refresh();
					   })
				   }else{
					   art.dialog.tips("删除失败");
				   }
			   }
		});
	 }
}

function edit(pid,title,type,id){
	var editid=document.getElementById('editrepository');
	$(editid).find("[name='id']").val(id);
	$(editid).find("[name='pid']").val(pid);
	$(editid).find("[name='title']").val(title);
	$(editid).find("[name='type']").val(type);
	 dialog = art.dialog({
	        title: "编辑清单标题",
	        lock:true,
	        content: editid
	    });
}


function sosuo(){
	var lpath =location.pathname;
	$("#soform").attr("action",lpath);
	$("#soform").submit();
}
function check(id,title){
	art.dialog.post({
		url : 'o_checktitle.do',
		data : {id:id,title : title},
		success : function(data){
			if(data.success){
				$("#repositoryfrom").submit();
				return true;
			}else{
				art.dialog.tips("重复的标题！");
				return false;
			}
		}
	})
}
function sub(){
	var id=$("#editrepository").find("[name='id']").val();
	var title=$("#editrepository").find("[name='title']").val();
	check(id,title);
}
</script>
</head>
<body>
	<div class="panel panel-info panel-content">
		<div class="panel-heading"> 
			  <form  id="soform" method="post"  action=""> 
				  <div class="input-group" style="width:200px;float: right;">
							<input type="text" class="form-control"  name="so_repositoryTitles"  value='${repositoryTitles!}' placeholder="清单标题"> 
							<span class="input-group-btn">
								<button class="btn btn-default" type="button" onclick="sosuo()">搜索</button>
							</span>
				  </div>
				  <div class="input-group" style="width:200px;float: right;">
			  	   <select class="form-control"  id="so_repositorytype" name="so_repositorytype"  onchange="sosuo()">
						<option [#if !repositorytype?? || repositorytype==0] selected="selected"  [/#if]  value="0"  >全部</option>
						<option [#if repositorytype?? && repositorytype==1 ] selected="selected"  [/#if]  value="1"  >设备名称</option>
						<option [#if repositorytype?? && repositorytype==2 ] selected="selected"  [/#if]  value="2"  >品牌</option>
						<option [#if repositorytype?? && repositorytype==3 ] selected="selected"  [/#if]  value="3"  >型号</option>
						<option [#if repositorytype?? && repositorytype==4 ] selected="selected"  [/#if]  value="4"  >单位</option>
						<option [#if repositorytype?? && repositorytype==5 ] selected="selected"  [/#if]  value="5"  >数量</option>
						<option [#if repositorytype?? && repositorytype==6 ] selected="selected"  [/#if]  value="6"  >技术参数描述</option>
					</select>
			      </div>
			  </form>
			  <button type="button" id="addrepositoryTitles"  class="btn btn-info"><span class="glyphicon glyphicon-plus"></span>&nbsp;新增清单标题</button>
		</div>
		<table class="table table-hover table-bordered">
			<tr>
				<th width="5%">#</th>
				<th width="10%">清单类目</th>
				<th width="20%">清单标题</th>
				<th width="20%">清单类别</th>
				<th width="15%">创建时间</th>
				<th width="15%">修改时间</th>
				<th width="20%">操作</th>
			</tr>
 
			[#list pagination.list as repositoryTitles]
			<tr>
				<td style="text-align: center">${pagination.pageSize * (pagination.pageNo-1)+repositoryTitles_index+1}</td>
				<td style="text-align: center">[#if repositoryTitles.pid==1]设备名称[/#if]
				    [#if repositoryTitles.pid==2]品牌[/#if]
				    [#if repositoryTitles.pid==3]型号[/#if]
				    [#if repositoryTitles.pid==4]单位[/#if]
				    [#if repositoryTitles.pid==5]数量[/#if]
				    [#if repositoryTitles.pid==6]技术参数描述[/#if]
				</td>
				<td style="text-align: center">${repositoryTitles.title!}</td>
				<td style="text-align: center">[#if repositoryTitles.type==0]全部[#elseif repositoryTitles.type==1]询价[#elseif repositoryTitles.type==2]报价[/#if]</td>
				<td style="text-align: center">${(repositoryTitles.createtime?string("yyyy-MM-dd"))!}</td>
				<td style="text-align: center">${(repositoryTitles.updatetime?string("yyyy-MM-dd"))!}</td>
				<td style="text-align: center">
					<input value="删除" type="button" onclick="del(${repositoryTitles.id});" class="btn btn-danger btn-xs" />
					<input value="编辑" type="button" onclick="edit(${repositoryTitles.pid!}, '${repositoryTitles.title!}','${repositoryTitles.type!}',${repositoryTitles.id});" class="btn btn-danger btn-xs" />
				</td>
			</tr>
			[/#list]
		</table>
		
		<div class="panel-footer">[@fenye p = pagination form = 'infoForm' /]</div>
	</div>
	
	<div id="editrepository" style="width: 500px;height:150px;display: none;">
		 <form id="repositoryfrom" action="o_editorAddTitle.do" method="post" class="form-horizontal" role="form">
		 		 <input type="hidden" name="id">
			     <div class="form-group">
				      <label  class="col-sm-2 control-label">清单类目</label>
				      <div class="col-sm-8">
				      <select id="pid" name="pid" class="form-control">
				       <option value="1">设备名称</option>
				       <option value="2">品牌</option>
				       <option value="3">型号</option>
				       <option value="4">单位</option>
				       <option value="5">数量</option>
				       <option value="6">技术参数描述</option>
				      </select>
				      </div>
			     </div>
			       <div class="form-group">
				      <label  class="col-sm-2 control-label">清单标题</label>
				      <div class="col-sm-8">
				         <input type="text" class="form-control"  
				            placeholder="请输入标题" min="1" maxlength="100" required="required" id="title" name="title">
				      </div>
			     </div>
			      <div class="form-group">
				      <label  class="col-sm-2 control-label">清单类别</label>
				      <div class="col-sm-8">
				      <select class="form-control" required="required" id="type" name="type">
				      <option value="0">全部</option>
				      <option value="1">询价</option>
				      <option value="2">报价</option>
				      </select>
				      </div>
			     </div>
   				<div class="form-group" style="margin-top: 10px;">
				      <div class="col-sm-offset-2 col-sm-8">
				         <button  type="button" onclick="sub()" class="btn btn-default">提交</button>
				      </div>
   				</div>
		 </form>
	</div>
</body>
</html>